home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / c / tox.lha / tox / main.c next >
C/C++ Source or Header  |  2002-10-20  |  2KB  |  96 lines

  1. /*-------------------------------------------------------------------------
  2.  * tox - an XML tokenizer
  3.  *
  4.  * Copyright (c) 2000 Eckhart Köppen
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.  * Boston, MA 02111-1307, USA.
  20.  *-----------------------------------------------------------------------*/
  21.  
  22. /* $Id: main.c,v 1.11 2002/05/01 03:14:27 koeppen Exp $ */
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "tox.h"
  27.  
  28. void element_callback (parser_state *);
  29. void word_callback (parser_state *);
  30. void ws_callback (parser_state *);
  31.  
  32. void element_callback (parser_state *parser)
  33. {
  34.     printf ("[%s]", parser->buffer);
  35. }
  36.  
  37. void word_callback (parser_state *parser)
  38. {
  39.     printf ("%s", parser->buffer);
  40. }
  41.  
  42. void ws_callback (parser_state *parser)
  43. {
  44.     printf ("%s", parser->buffer);
  45. }
  46.  
  47. int main (int argc, char *argv[])
  48. {
  49.     FILE *f;
  50.     parser_state parser;
  51.     unsigned char buffer[128];
  52.     int n;
  53.     unsigned char localtext[100];
  54.  
  55.     memset (&parser, 0, sizeof (parser_state));
  56.     parser.text = localtext;
  57.  
  58.    parser.char_width = 1;
  59.  
  60.    parser.little_endian = 0;
  61.     
  62.     parser.state = STATE_CONTENT;
  63.  
  64.     parser.buffer = buffer;
  65.     parser.maxbuf = 127;
  66.     parser.pump = 0;
  67.     parser.bcurrent = 0;
  68.  
  69.     parser.element_callback = element_callback;
  70.     parser.word_callback = word_callback;
  71.     parser.ws_callback = ws_callback;
  72.  
  73.  
  74.    f = fopen (argv[1], "rb");
  75.     while (!feof (f) && parser.state != STATE_ERROR) {
  76.         n = fread (localtext, 1, 1, f);
  77.         localtext[n] = '\0';
  78.  
  79.         parser.current = 0;
  80.         parser.maxtext = n;
  81.  
  82.         tox_parse (&parser);
  83.     }
  84.     printf ("%d %s\n", parser.state, &parser.text[parser.current]);
  85.  
  86.    fclose (f);
  87. }
  88.  
  89. /*
  90.  * Local variables:
  91.  * tab-width: 4
  92.  * c-basic-offset: 4
  93.  * End:
  94.  */
  95.  
  96.